<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');
class Fill_coin extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->verify_user();
	}

	public function index()
	{
		$d['coins'] = $this->d->rows(array('table' => 'coin'));
		$this->view('fill_coin', $d);
	}

	public function data()
	{
		$page = ($this->input->post('page') ? intval($this->input->post('page')) : 1);
		$rows = ($this->input->post('rows') ? intval($this->input->post('rows')) : 10);
		$id = intval($this->input->post('id'));
		$status = $this->input->post('status');
		$username = $this->input->post('username');
		$start = $this->input->post('start');
		$end = $this->input->post('end');
		$coin_id = $this->input->post('coin_id');
		$where[1] = 1;

		if ($username) {
			$user = $this->db->where('username', $username)->get('user')->row_array();
			$where['user_id'] = $user['id'];
		}

		if ($start) {
			$where['add_time>='] = strtotime($start);
		}

		if ($end) {
			$where['add_time<='] = strtotime($end);
		}

		if ($id) {
			$where['id'] = $id;
		}

		if ($coin_id) {
			$where['coin_id'] = $coin_id;
		}

		if ($id) {
			$where['id'] = $id;
		}

		if (0 <= $status) {
			$where['status'] = $status;
		}

		$result['total'] = $this->db->where($where)->count_all_results('fill_coin');
		$start = ($page - 1) * $rows;
		$list = $this->db->where($where)->limit($rows, $start)->get('fill_coin')->result_array();

		foreach ($list as $k => $v) {
			$list[$k]['add_time'] = date('Y-m-d H:i', $v['add_time']);
			$list[$k]['username'] = $this->d->field(array('table' => 'user', 'field' => 'username', 'where' => 'id=' . $v['user_id']));
			$list[$k]['address'] = $this->d->field(array('table' => 'xnb', 'field' => 'address', 'where' => 'coin_id=' . $v['coin_id'] . ' and user_id' . $v['user_id']));
			$list[$k]['coin_name'] = $this->d->field(array('table' => 'coin', 'where' => 'id=' . $v['coin_id'], 'field' => 'cn_name'));
			$list[$k]['status'] = $v['status'] == 0 ? '未转入' : '已转入';
		}

		$result['rows'] = $list;
		echo json_encode($result);
	}
}

?>
